package com.woniu.guoguo.dao;

import com.woniu.guoguo.model.MenuImg;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.guoguo.controller.component.MenuInfo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Richie
 * @since 2020-11-03
 */
public interface MenuImgMapper extends BaseMapper<MenuImg> {

    @Select("select img_path from menu_img where menu_id=#{id}")
    List<String> findImagesByMenuId(Integer menuId);

    @Select("SELECT\n" +
            "\tt1.menu_id,t1.type,t1.menu_name,t1.price,t1.description,t1.discounts,t1.vip_price,t1.integral,t1.sale_num,\n" +
            "\t(\n" +
            "\t\tSELECT\n" +
            "\t\t\tmenu_img.img_path \n" +
            "\t\tFROM\n" +
            "\t\t\tmenu_img\n" +
            "\t\tWHERE\n" +
            "\t\t\tmenu_img.menu_id = t1.menu_id\n" +
            "\t\tLIMIT 0, 1 \n" +
            "\t) as img_path\n" +
            "FROM\n" +
            "\tmenu AS t1\n" +
            "\twhere status = 1\n"+
            "ORDER BY t1.sale_num desc \n" +
            "LIMIT 0,6\n")
    List<MenuInfo> queryMenu();

}
